package com.example.demo.service;

import android.nfc.Tag;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

import com.example.demo.LoginActivity;
import com.example.demo.constants.API;
import com.example.demo.tools.HttpUtil;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.Map;

import static android.content.ContentValues.TAG;


public class JokeService {

    private HttpUtil httpUtil;


    public JokeService(){
        httpUtil = new HttpUtil();
    }


    public void allJoke(Handler handler){
        JsonObject json = new JsonObject();

        json.addProperty("page",1);
        json.addProperty("row",10);
        json.addProperty("tag","-1");
        String data = json.toString();
        new Thread(new Runnable() {
            @Override
            public void run() {
                //通过路由 传入数据 访问后台
                String json = httpUtil.sendRequestByPost(API.ALLJOKE, data);
                //子线程返回数据到主线程
                Message msg = new Message();
                Bundle bundle = new Bundle();
                bundle.putString("result",json);
                msg.setData(bundle);
                //子线程发送数据
                handler.sendMessage(msg);
            }
        }).start();
    }

}
